package com.zpark.it.service.impl;

import com.zpark.it.clients.CategoryClient;
import com.zpark.it.param.PageParam;
import com.zpark.it.pojo.Category;
import com.zpark.it.service.CategoryService;
import com.zpark.it.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Title: CategoryServiceImpl
 * @Author Charles
 * @Package com.zpark.it.service.impl
 * @Date 2023/7/27 11:49
 */
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryClient categoryClient;
    /**
     * 分页查询
     *
     * @param pageParam
     * @return
     */
    @Override
    @Cacheable(value = "list.category",key = "#pageParam.getCurrentPage()+'-'+#pageParam.getPageSize()")
    public R pageList(PageParam pageParam) {
        R r = categoryClient.adminPageList(pageParam);
        return r;
    }

    /**
     * 进行分类数据添加
     *
     * @param category
     * @return
     */
    @Override
    @CacheEvict(value = "list.category",allEntries = true)
    public R save(Category category) {
        R r = categoryClient.adminSave(category);

        return r;
    }

    /**
     * 根据id删除类别名称
     *
     * @param categoryId
     * @return
     */
    @Override
    @CacheEvict(value = "list.category",allEntries = true)
    public R remove(Integer categoryId) {

        R r = categoryClient.adminRemove(categoryId);
        return r;
    }

    /**
     * 修改类别信息
     *
     * @param category
     * @return
     */
    @Override
    @CacheEvict(value = "list.category",allEntries = true)
    public R update(Category category) {

        R r = categoryClient.adminUpdate(category);
        return r;
    }
}
